<template>
  <ul class="row list-unstyled">
    <li v-for="column in columnList" :key="column.id" class="col-4 mt-4">
      <div class="card h-200 shadow-sm">
        <div class="card-body text-center">
          <img
            :src="column.avatar"
            alt="column.title"
            class="rounded-circle border border-light w-25 my-3"
          />
          <h5 class="card-title">{{ column.title }}</h5>
          <p class="card-text text-start">{{ column.description }}</p>
          <a href="#" class="btn btn-outline-primary">进入专栏</a>
        </div>
      </div>
    </li>
  </ul>
</template>

<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'
export interface ColumnProps {
  id: number;
  title: string;
  avatar?: string;
  description: string;
}

export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup (props) {
    const columnList = computed(() => {
      return props.list.map(column => {
        if (!column.avatar) {
          column.avatar = 'https://bpic.588ku.com/element_pic/20/07/01/a5d1d2ef3b15734009f10d083d012383.jpg!/fw/253/quality/90/unsharp/true/compress/true'
        }
        return column
      })
    })
    return {
      columnList
    }
  }
})

</script>

<style lang="less">
</style>
